<template>
  <div class="user">
    <el-dropdown>
      <span class="user-info">
        <el-avatar
          :size="35"
          src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
        />
        <span>{{ userInfo.userName }}</span>
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="logout">
            <el-icon>
              <CircleClose />
            </el-icon>
            <span>退出登录</span>
          </el-dropdown-item>
          <el-dropdown-item divided>
            <el-icon>
              <InfoFilled />
            </el-icon>
            <span>个人信息</span>
          </el-dropdown-item>
          <el-dropdown-item>
            <el-icon>
              <Unlock />
            </el-icon>
            <span>修改密码</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script lang="ts" setup>
import router from '@/router'
import useLoginStore from '@/store/login/loginstore'

const {userInfo} = useLoginStore()

const logout = () => {
  localStorage.removeItem('token')
  localStorage.removeItem('userInfo')
  router.push('/login')
}

</script>

<style scoped lang="scss">
.user {
  display: inline-flex;
  align-items: center;
  margin-right: 20px;
  cursor: pointer;

  .el-avatar {
    margin-right: 10px;
  }

  .user-info {
    display: flex;
    align-items: center;
    font-size: 22px;
  }

  :global(.el-dropdown-menu__item) {
    line-height: 30px;
    padding: 5px 20px;
  }
}
</style>
